smol
A small and fast async runtime.
Examples
Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
use TcpStream;
use ;
This example uses async-net
for networking, but you can also use the primitive Async
type. See the full code.
Look inside the examples directory for more.
Compatibility
All async libraries work with smol out of the box.
The only exception is tokio, which is traditionally incompatible with futures and crashes when called from other executors. Fortunately, there are ways around it.
Enable the tokio02
feature flag and smol::run()
will create a minimal
tokio runtime for its libraries:
[]
= { = "0.3", = ["tokio02"] }
TLS certificate
Some code examples are using TLS for authentication. The repository contains a self-signed certificate usable for testing, but it should not be used for real-world scenarios. Browsers and tools like curl will show this certificate as insecure.
In browsers, accept the security prompt or use curl -k
on the
command line to bypass security warnings.
The certificate file was generated using minica and openssl:
minica --domains localhost -ip-addresses 127.0.0.1 -ca-cert certificate.pem
openssl pkcs12 -export -out identity.pfx -inkey localhost/key.pem -in localhost/cert.pem
Another useful tool for making certificates is mkcert.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.